package cn.terminus.common;

import cn.terminus.result.common.context.TerminusCallContext;
import cn.terminus.result.common.context.TerminusSessionObject;
import cn.terminus.result.common.context.business.BusinessContext;
import cn.terminus.result.common.context.holder.TerminusSessionContextHolder;
import cn.terminus.result.common.context.user.UserContext;
import cn.terminus.result.common.page.TerminusPageInfo;
import org.jeasy.random.EasyRandom;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import javax.annotation.PostConstruct;

/**
 * ApplicationTest
 *
 * @author tsl081
 * 2021/7/2 11:47
 **/
@ExtendWith(SpringExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
public class ApplicationTestInit {
    public Logger logger = LoggerFactory.getLogger(this.getClass());

    protected EasyRandom easyRandom = new EasyRandom();

    protected TerminusCallContext callContext;

    protected TerminusPageInfo pageInfo;

    protected Long id;

    @Autowired
    private TerminusSessionContextHolder terminusSessionContextHolder;

    @PostConstruct
    public void init() {
        callContext = new TerminusCallContext();
        callContext.setApplicationId(459296664042078208L);
        callContext.setServiceCode("100011");
        BusinessContext business = new BusinessContext();
        business.setBusinessId(1L);
        callContext.setBusiness(business);
        callContext.setServiceCode("1");
        UserContext userContext = new UserContext();
        userContext.setCaller(0L);
        callContext.setUser(userContext);
        pageInfo = new TerminusPageInfo(1, 10);
        TerminusSessionObject sessionObject = new TerminusSessionObject(callContext.getUser().getCaller(), "1", 1L, "l", "单元测试",false);
        this.terminusSessionContextHolder.putSession(sessionObject);
    }
}
